Change in openvpn[master]: PUSH_UPDATE server: remove old IP(s) from vhash after sending a messa...
A message that is not in the archive (sent off-list or not yet received): gerrit.1759855064000.I07a8ddd9026eef64b6f5abde98702a9801616a5f@...2715...
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
to review the following change.
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
When sending a PUSH_UPDATE containing an ifconfig(-ipv6) option, we must add the new IP to the multi_context vhash (hash table of the clients indexed by virtual IPs). Now in addition to adding new client IPs, old IPs are also removed from vhash, allowing for a more complete update.
---
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/push_util.c
M tests/unit_tests/openvpn/test_push_update_msg.c
6 files changed, 187 insertions(+), 74 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/53/1253/1
src/openvpn/multi.c +121 -29
@@ -4269,46 +4269,138 @@close_instance (top); } +/* Searches for the address and deletes it if it is owned by the multi_instance */ +static void +multi_unlearn_addr (struct multi_context *m,struct multi_instance *mi,const struct mroute_addr *addr) +{ +struct hash_element *he; +const uint32_t hv =hash_value (m->vhash, addr); +struct hash_bucket *bucket =hash_bucket (m->vhash, hv); +struct multi_route *r =NULL ; + +/* if route currently exists, get the instance which owns it */ + he =hash_lookup_fast (m->vhash, bucket, addr, hv); +if (he) + { + r = (struct multi_route *)he->value; + } + +/* if the route does not exist or exists but is not owned by the current instance, return */ +if (!r || r->instance != mi) + { +return ; + } + +struct gc_arena gc =gc_new (); +dmsg (D_MULTI_DEBUG ,"MULTI: DEL %s" ,mroute_addr_print (&r->addr, &gc)); +msg (D_MULTI_LOW ,"MULTI: Remove: %s -> %s" ,mroute_addr_print (&r->addr, &gc),multi_instance_string (mi, false, &gc)); +learn_address_script (m,NULL ,"delete" , &r->addr); +hash_remove_by_value (m->vhash, r); +route_quota_dec (mi); +multi_instance_dec_refcount (mi); + +gc_free (&gc); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a The new IPv4 address in host byte order +*/ +static void +multi_unlearn_in_addr_t (struct multi_context *m,struct multi_instance *mi,in_addr_t a) +{ +struct openvpn_sockaddr remote_si; +struct mroute_addr addr = {0 }; + +CLEAR (remote_si); + remote_si.addr.in4.sin_family =AF_INET ; + remote_si.addr.in4.sin_addr.s_addr = a; + addr.proto =0 ; +ASSERT (mroute_extract_openvpn_sockaddr (&addr, &remote_si, false)); + +multi_unlearn_addr (m, mi, &addr); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a6 The new IPv6 address in host byte order +*/ +static void +multi_unlearn_in6_addr (struct multi_context *m,struct multi_instance *mi,struct in6_addr a6) +{ +struct mroute_addr addr = {0 }; + + addr.len =16 ; + addr.type =MR_ADDR_IPV6 ; + addr.netbits =0 ; + addr.v6.addr = a6; + +multi_unlearn_addr (m, mi, &addr); +} +/** * Update the vhash with new IP/IPv6 addresses in the multi_context when a * push-update message containing ifconfig/ifconfig-ipv6 options is sent -* from the server. This function should be called after a push-update -* and old_ip/old_ipv6 are the previous addresses of the client in -* ctx->options.ifconfig_local and ctx->options.ifconfig_ipv6_local. +* from the server. +* +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param new_ip The new IPv4 address or NULL if no change +* @param new_ipv6 The new IPv6 address or NULL if no change */ void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) { -struct in_addr addr; -struct in6_addr new_ipv6; - -if ((mi->context.options.ifconfig_local && (!old_ip ||strcmp (old_ip, mi->context.options.ifconfig_local))) - &&inet_pton (AF_INET , mi->context.options.ifconfig_local, &addr) ==1 ) +if (new_ip) { -in_addr_t new_ip =ntohl (addr.s_addr); +struct in_addr new_addr; +struct in_addr old_addr; +CLEAR (new_addr); +CLEAR (old_addr); + +/* Remove old IP */ +if (mi->context.c2.push_ifconfig_defined) + { + old_addr.s_addr =ntohl (mi->context.c2.push_ifconfig_local); + +multi_unlearn_in_addr_t (m, mi, old_addr.s_addr); + mi->context.c2.push_ifconfig_defined = false; + mi->context.c2.push_ifconfig_local =0 ; + }/* Add new IP */ -multi_learn_in_addr_t (m, mi, new_ip,-1 , true); +if (inet_pton (AF_INET , new_ip, &new_addr) ==1 + &&multi_learn_in_addr_t (m, mi,ntohl (new_addr.s_addr),-1 , true)) + { + mi->context.c2.push_ifconfig_defined = true; + mi->context.c2.push_ifconfig_local = new_addr.s_addr; + } } -/* TO DO: -* else if (old_ip) -* { -* // remove old IP -* } -*/ - -if ((mi->context.options.ifconfig_ipv6_local && (!old_ipv6 ||strcmp (old_ipv6, mi->context.options.ifconfig_ipv6_local))) - &&inet_pton (AF_INET6 , mi->context.options.ifconfig_ipv6_local, &new_ipv6) ==1 ) +if (new_ipv6) { -/* Add new IPv6 */ -multi_learn_in6_addr (m, mi, new_ipv6,-1 , true); - } +struct in6_addr new_addr6; +struct in6_addr old_addr6; +CLEAR (new_addr6); +CLEAR (old_addr6); -/* TO DO: -* else if (old_ipv6) -* { -* // remove old IPv6 -* } -*/ +/* Remove old IPv6 */ +if (mi->context.c2.push_ifconfig_ipv6_defined) + { + old_addr6 = mi->context.c2.push_ifconfig_ipv6_local; +multi_unlearn_in6_addr (m, mi, old_addr6); + mi->context.c2.push_ifconfig_ipv6_defined = false; +CLEAR (mi->context.c2.push_ifconfig_ipv6_local); + } + +/* Add new IPv6 */ +if (inet_pton (AF_INET6 , new_ipv6, &new_addr6) ==1 + &&multi_learn_in6_addr (m, mi, new_addr6,-1 , true)) + { + mi->context.c2.push_ifconfig_ipv6_defined = true; + mi->context.c2.push_ifconfig_ipv6_local = new_addr6; + } + } }
src/openvpn/multi.h +1 -1
@@ -692,6 +692,6 @@#endif void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6); +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6);#endif /* MULTI_H */
src/openvpn/push.c +1 -1
@@ -1112,7 +1112,7 @@ }else if (honor_received_options &&buf_string_compare_advance (&buf, push_update_cmd)) { -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_incoming_push_update (c, permission_mask, option_types_found, &buf); }else {
src/openvpn/push.h +1 -3
@@ -65,7 +65,6 @@* @param option_types_found A pointer to a variable that will be filled with the types of options * found in the message. * @param buf A buffer containing the received message. -* @param msg_sender A boolean indicating if function is called by the message sender (server). * * @return * - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied.
@@ -75,8 +74,7 @@*/ int process_incoming_push_update (struct context *c,unsigned int permission_mask, -unsigned int *option_types_found,struct buffer *buf, -bool msg_sender); +unsigned int *option_types_found,struct buffer *buf); int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options, unsigned int permission_mask,
src/openvpn/push_util.c +62 -39
171 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +1 -1
@@ -95,7 +95,7 @@ }else if (honor_received_options &&buf_string_compare_advance (&buf, push_update_cmd)) { -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_incoming_push_update (c, permission_mask, option_types_found, &buf); }else {
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 1
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Attention is currently required from: flichtenheld, mrbff, plaisthos.
cron2 has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email )
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
Patch Set 1: Code-Review-1
(2 comments)
Patchset:
PS1:
code duplication
File src/openvpn/push_util.c:
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/f66e2fcf_a5816c90?usp=email :
PS1, Line 90: }
This is code duplication of the finest sort - please do not do that. This function is practically identical to process_incoming_push_update(), except for the "throw signal" branch. Please do not do that.
If you want to make clear that this is not "incoming" only, rename it to process_push_update().
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 1
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Tue, 07 Oct 2025 16:47:57 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: cron2, flichtenheld, mrbff, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
to look at the new patch set (#2).
The following approvals got outdated and were removed:
Code-Review-1 by cron2
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
When sending a PUSH_UPDATE containing an ifconfig(-ipv6) option, we must add the new IP to the multi_context vhash (hash table of the clients indexed by virtual IPs). Now in addition to adding new client IPs, old IPs are also removed from vhash, allowing for a more complete update.
---
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/push_util.c
M tests/unit_tests/openvpn/test_push_update_msg.c
6 files changed, 155 insertions(+), 72 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/53/1253/2
src/openvpn/multi.c +121 -29
@@ -4269,46 +4269,138 @@close_instance (top); } +/* Searches for the address and deletes it if it is owned by the multi_instance */ +static void +multi_unlearn_addr (struct multi_context *m,struct multi_instance *mi,const struct mroute_addr *addr) +{ +struct hash_element *he; +const uint32_t hv =hash_value (m->vhash, addr); +struct hash_bucket *bucket =hash_bucket (m->vhash, hv); +struct multi_route *r =NULL ; + +/* if route currently exists, get the instance which owns it */ + he =hash_lookup_fast (m->vhash, bucket, addr, hv); +if (he) + { + r = (struct multi_route *)he->value; + } + +/* if the route does not exist or exists but is not owned by the current instance, return */ +if (!r || r->instance != mi) + { +return ; + } + +struct gc_arena gc =gc_new (); +dmsg (D_MULTI_DEBUG ,"MULTI: DEL %s" ,mroute_addr_print (&r->addr, &gc)); +msg (D_MULTI_LOW ,"MULTI: Remove: %s -> %s" ,mroute_addr_print (&r->addr, &gc),multi_instance_string (mi, false, &gc)); +learn_address_script (m,NULL ,"delete" , &r->addr); +hash_remove_by_value (m->vhash, r); +route_quota_dec (mi); +multi_instance_dec_refcount (mi); + +gc_free (&gc); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a The new IPv4 address in host byte order +*/ +static void +multi_unlearn_in_addr_t (struct multi_context *m,struct multi_instance *mi,in_addr_t a) +{ +struct openvpn_sockaddr remote_si; +struct mroute_addr addr = {0 }; + +CLEAR (remote_si); + remote_si.addr.in4.sin_family =AF_INET ; + remote_si.addr.in4.sin_addr.s_addr = a; + addr.proto =0 ; +ASSERT (mroute_extract_openvpn_sockaddr (&addr, &remote_si, false)); + +multi_unlearn_addr (m, mi, &addr); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a6 The new IPv6 address in host byte order +*/ +static void +multi_unlearn_in6_addr (struct multi_context *m,struct multi_instance *mi,struct in6_addr a6) +{ +struct mroute_addr addr = {0 }; + + addr.len =16 ; + addr.type =MR_ADDR_IPV6 ; + addr.netbits =0 ; + addr.v6.addr = a6; + +multi_unlearn_addr (m, mi, &addr); +} +/** * Update the vhash with new IP/IPv6 addresses in the multi_context when a * push-update message containing ifconfig/ifconfig-ipv6 options is sent -* from the server. This function should be called after a push-update -* and old_ip/old_ipv6 are the previous addresses of the client in -* ctx->options.ifconfig_local and ctx->options.ifconfig_ipv6_local. +* from the server. +* +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param new_ip The new IPv4 address or NULL if no change +* @param new_ipv6 The new IPv6 address or NULL if no change */ void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) { -struct in_addr addr; -struct in6_addr new_ipv6; - -if ((mi->context.options.ifconfig_local && (!old_ip ||strcmp (old_ip, mi->context.options.ifconfig_local))) - &&inet_pton (AF_INET , mi->context.options.ifconfig_local, &addr) ==1 ) +if (new_ip) { -in_addr_t new_ip =ntohl (addr.s_addr); +struct in_addr new_addr; +struct in_addr old_addr; +CLEAR (new_addr); +CLEAR (old_addr); + +/* Remove old IP */ +if (mi->context.c2.push_ifconfig_defined) + { + old_addr.s_addr =ntohl (mi->context.c2.push_ifconfig_local); + +multi_unlearn_in_addr_t (m, mi, old_addr.s_addr); + mi->context.c2.push_ifconfig_defined = false; + mi->context.c2.push_ifconfig_local =0 ; + }/* Add new IP */ -multi_learn_in_addr_t (m, mi, new_ip,-1 , true); +if (inet_pton (AF_INET , new_ip, &new_addr) ==1 + &&multi_learn_in_addr_t (m, mi,ntohl (new_addr.s_addr),-1 , true)) + { + mi->context.c2.push_ifconfig_defined = true; + mi->context.c2.push_ifconfig_local = new_addr.s_addr; + } } -/* TO DO: -* else if (old_ip) -* { -* // remove old IP -* } -*/ - -if ((mi->context.options.ifconfig_ipv6_local && (!old_ipv6 ||strcmp (old_ipv6, mi->context.options.ifconfig_ipv6_local))) - &&inet_pton (AF_INET6 , mi->context.options.ifconfig_ipv6_local, &new_ipv6) ==1 ) +if (new_ipv6) { -/* Add new IPv6 */ -multi_learn_in6_addr (m, mi, new_ipv6,-1 , true); - } +struct in6_addr new_addr6; +struct in6_addr old_addr6; +CLEAR (new_addr6); +CLEAR (old_addr6); -/* TO DO: -* else if (old_ipv6) -* { -* // remove old IPv6 -* } -*/ +/* Remove old IPv6 */ +if (mi->context.c2.push_ifconfig_ipv6_defined) + { + old_addr6 = mi->context.c2.push_ifconfig_ipv6_local; +multi_unlearn_in6_addr (m, mi, old_addr6); + mi->context.c2.push_ifconfig_ipv6_defined = false; +CLEAR (mi->context.c2.push_ifconfig_ipv6_local); + } + +/* Add new IPv6 */ +if (inet_pton (AF_INET6 , new_ipv6, &new_addr6) ==1 + &&multi_learn_in6_addr (m, mi, new_addr6,-1 , true)) + { + mi->context.c2.push_ifconfig_ipv6_defined = true; + mi->context.c2.push_ifconfig_ipv6_local = new_addr6; + } + } }
src/openvpn/multi.h +1 -1
@@ -692,6 +692,6 @@#endif void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6); +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6);#endif /* MULTI_H */
src/openvpn/push.c +1 -1
@@ -1112,7 +1112,7 @@ }else if (honor_received_options &&buf_string_compare_advance (&buf, push_update_cmd)) { -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
src/openvpn/push.h +5 -4
@@ -61,11 +61,13 @@* message has not yet been received. * * @param c The context for the operation. +* @param o The options structure to be updated with the received push options. * @param permission_mask The permission mask specifying which options are allowed to be pulled. * @param option_types_found A pointer to a variable that will be filled with the types of options * found in the message. * @param buf A buffer containing the received message. -* @param msg_sender A boolean indicating if function is called by the message sender (server). +* @param msg_sender A boolean indicating if the message is being processed on the client (false) +* or on the server (true). * * @return * - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied.
@@ -74,9 +76,8 @@* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. */ -int process_incoming_push_update (struct context *c,unsigned int permission_mask, -unsigned int *option_types_found,struct buffer *buf, -bool msg_sender); +int process_push_update (struct context *c,struct options *o,unsigned int permission_mask, +unsigned int *option_types_found,struct buffer *buf,bool msg_sender); int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options, unsigned int permission_mask,
src/openvpn/push_util.c +26 -36
132 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +1 -1
@@ -95,7 +95,7 @@ }else if (honor_received_options &&buf_string_compare_advance (&buf, push_update_cmd)) { -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 2
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Attention is currently required from: cron2, flichtenheld, plaisthos.
mrbff has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email )
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
Patch Set 1:
(2 comments)
Patchset:
PS1:
Quoted 1 line
code duplication
Done
File src/openvpn/push_util.c:
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/94ade16a_b3ca4ef2?usp=email :
PS1, Line 90: }
Quoted 1 line
This is code duplication of the finest sort - please do not do that. […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 1
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 07 Oct 2025 19:17:59 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Attention is currently required from: cron2, flichtenheld, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
to look at the new patch set (#3).
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
When sending a PUSH_UPDATE containing an ifconfig(-ipv6) option, we must add the new IP to the multi_context vhash (hash table of the clients indexed by virtual IPs). Now in addition to adding new client IPs, old IPs are also removed from vhash, allowing for a more complete update.
---
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/push_util.c
M tests/unit_tests/openvpn/test_push_update_msg.c
6 files changed, 156 insertions(+), 72 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/53/1253/3
src/openvpn/multi.c +121 -29
@@ -4269,46 +4269,138 @@close_instance (top); } +/* Searches for the address and deletes it if it is owned by the multi_instance */ +static void +multi_unlearn_addr (struct multi_context *m,struct multi_instance *mi,const struct mroute_addr *addr) +{ +struct hash_element *he; +const uint32_t hv =hash_value (m->vhash, addr); +struct hash_bucket *bucket =hash_bucket (m->vhash, hv); +struct multi_route *r =NULL ; + +/* if route currently exists, get the instance which owns it */ + he =hash_lookup_fast (m->vhash, bucket, addr, hv); +if (he) + { + r = (struct multi_route *)he->value; + } + +/* if the route does not exist or exists but is not owned by the current instance, return */ +if (!r || r->instance != mi) + { +return ; + } + +struct gc_arena gc =gc_new (); +dmsg (D_MULTI_DEBUG ,"MULTI: DEL %s" ,mroute_addr_print (&r->addr, &gc)); +msg (D_MULTI_LOW ,"MULTI: Remove: %s -> %s" ,mroute_addr_print (&r->addr, &gc),multi_instance_string (mi, false, &gc)); +learn_address_script (m,NULL ,"delete" , &r->addr); +hash_remove_by_value (m->vhash, r); +route_quota_dec (mi); +multi_instance_dec_refcount (mi); + +gc_free (&gc); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a The new IPv4 address in host byte order +*/ +static void +multi_unlearn_in_addr_t (struct multi_context *m,struct multi_instance *mi,in_addr_t a) +{ +struct openvpn_sockaddr remote_si; +struct mroute_addr addr = {0 }; + +CLEAR (remote_si); + remote_si.addr.in4.sin_family =AF_INET ; + remote_si.addr.in4.sin_addr.s_addr = a; + addr.proto =0 ; +ASSERT (mroute_extract_openvpn_sockaddr (&addr, &remote_si, false)); + +multi_unlearn_addr (m, mi, &addr); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a6 The new IPv6 address in host byte order +*/ +static void +multi_unlearn_in6_addr (struct multi_context *m,struct multi_instance *mi,struct in6_addr a6) +{ +struct mroute_addr addr = {0 }; + + addr.len =16 ; + addr.type =MR_ADDR_IPV6 ; + addr.netbits =0 ; + addr.v6.addr = a6; + +multi_unlearn_addr (m, mi, &addr); +} +/** * Update the vhash with new IP/IPv6 addresses in the multi_context when a * push-update message containing ifconfig/ifconfig-ipv6 options is sent -* from the server. This function should be called after a push-update -* and old_ip/old_ipv6 are the previous addresses of the client in -* ctx->options.ifconfig_local and ctx->options.ifconfig_ipv6_local. +* from the server. +* +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param new_ip The new IPv4 address or NULL if no change +* @param new_ipv6 The new IPv6 address or NULL if no change */ void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) { -struct in_addr addr; -struct in6_addr new_ipv6; - -if ((mi->context.options.ifconfig_local && (!old_ip ||strcmp (old_ip, mi->context.options.ifconfig_local))) - &&inet_pton (AF_INET , mi->context.options.ifconfig_local, &addr) ==1 ) +if (new_ip) { -in_addr_t new_ip =ntohl (addr.s_addr); +struct in_addr new_addr; +struct in_addr old_addr; +CLEAR (new_addr); +CLEAR (old_addr); + +/* Remove old IP */ +if (mi->context.c2.push_ifconfig_defined) + { + old_addr.s_addr =ntohl (mi->context.c2.push_ifconfig_local); + +multi_unlearn_in_addr_t (m, mi, old_addr.s_addr); + mi->context.c2.push_ifconfig_defined = false; + mi->context.c2.push_ifconfig_local =0 ; + }/* Add new IP */ -multi_learn_in_addr_t (m, mi, new_ip,-1 , true); +if (inet_pton (AF_INET , new_ip, &new_addr) ==1 + &&multi_learn_in_addr_t (m, mi,ntohl (new_addr.s_addr),-1 , true)) + { + mi->context.c2.push_ifconfig_defined = true; + mi->context.c2.push_ifconfig_local = new_addr.s_addr; + } } -/* TO DO: -* else if (old_ip) -* { -* // remove old IP -* } -*/ - -if ((mi->context.options.ifconfig_ipv6_local && (!old_ipv6 ||strcmp (old_ipv6, mi->context.options.ifconfig_ipv6_local))) - &&inet_pton (AF_INET6 , mi->context.options.ifconfig_ipv6_local, &new_ipv6) ==1 ) +if (new_ipv6) { -/* Add new IPv6 */ -multi_learn_in6_addr (m, mi, new_ipv6,-1 , true); - } +struct in6_addr new_addr6; +struct in6_addr old_addr6; +CLEAR (new_addr6); +CLEAR (old_addr6); -/* TO DO: -* else if (old_ipv6) -* { -* // remove old IPv6 -* } -*/ +/* Remove old IPv6 */ +if (mi->context.c2.push_ifconfig_ipv6_defined) + { + old_addr6 = mi->context.c2.push_ifconfig_ipv6_local; +multi_unlearn_in6_addr (m, mi, old_addr6); + mi->context.c2.push_ifconfig_ipv6_defined = false; +CLEAR (mi->context.c2.push_ifconfig_ipv6_local); + } + +/* Add new IPv6 */ +if (inet_pton (AF_INET6 , new_ipv6, &new_addr6) ==1 + &&multi_learn_in6_addr (m, mi, new_addr6,-1 , true)) + { + mi->context.c2.push_ifconfig_ipv6_defined = true; + mi->context.c2.push_ifconfig_ipv6_local = new_addr6; + } + } }
src/openvpn/multi.h +1 -1
@@ -692,6 +692,6 @@#endif void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6); +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6);#endif /* MULTI_H */
src/openvpn/push.c +1 -1
@@ -1118,7 +1118,7 @@ " To be able to process PUSH_UPDATE messages, be sure to use the --disable-dco option.");return PUSH_MSG_ERROR ; } -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
src/openvpn/push.h +5 -4
@@ -61,11 +61,13 @@* message has not yet been received. * * @param c The context for the operation. +* @param o The options structure to be updated with the received push options. * @param permission_mask The permission mask specifying which options are allowed to be pulled. * @param option_types_found A pointer to a variable that will be filled with the types of options * found in the message. * @param buf A buffer containing the received message. -* @param msg_sender A boolean indicating if function is called by the message sender (server). +* @param msg_sender A boolean indicating if the message is being processed on the client (false) +* or on the server (true). * * @return * - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied.
@@ -74,9 +76,8 @@* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. */ -int process_incoming_push_update (struct context *c,unsigned int permission_mask, -unsigned int *option_types_found,struct buffer *buf, -bool msg_sender); +int process_push_update (struct context *c,struct options *o,unsigned int permission_mask, +unsigned int *option_types_found,struct buffer *buf,bool msg_sender); int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options, unsigned int permission_mask,
src/openvpn/push_util.c +26 -35
129 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +2 -2
@@ -29,7 +29,7 @@ }void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) {return ; }
@@ -95,7 +95,7 @@ }else if (honor_received_options &&buf_string_compare_advance (&buf, push_update_cmd)) { -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 3
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Attention is currently required from: flichtenheld, mrbff, plaisthos.
cron2 has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email )
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
Patch Set 3: Code-Review-1
(7 comments)
Patchset:
PS3:
I like this latest version, and it should work nicely.
There might be a missing free() - this needs to be checked. While at it, I've found a few other things that could use a bit of polishing.
File src/openvpn/multi.c:
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/723a899a_4779f06b?usp=email :
PS3, Line 4296: msg(D_MULTI_LOW, "MULTI: Remove: %s -> %s", mroute_addr_print(&r->addr, &gc), multi_instance_string(mi, false, &gc));
this is too much logging ;-)
I'd remove one of them, and change the other to include something like MULTI: multi_unlearn_addr(): DEL %s so it's clear it's not the normal "MULTI: DEL" path.
Also, if we want to be totally fancy, we could use the mi prefix code here
``` set_prefix(mi); msg(...) // no multi_instance_string() needed, as that's handled by msg_set_prefix() clear_prefix(); ```
as for the message level, I'd use D_MULTI_LOW (as that is used by multi.c for the "Learn" message).
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/80047d20_27d7418e?usp=email :
PS3, Line 4301:
we might have a memleak here. I looked at the code in "multi.c" that deletes mroutes (check_stale_routes(), multi_reap_range()), and those call multi_route_del(r) to do
```
route_quota_dec(mi);
multi_instance_dec_refcount(mi);
free(route);
```so you have the first two here, but not the free() - not 100% sure if this is required, but it smells like it.
(hash_remove_by_value() seems to not do anything about the thing pointed to)
Maybe just calling multi_route_del(r) here is the right thing (after the hash_remove_by_value() call, to avoid a use-after-free)?
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/f301c3e7_e77a6296?usp=email :
PS3, Line 4320: ASSERT(mroute_extract_openvpn_sockaddr(&addr, &remote_si, false));
This works, but feels more clumsy than needed - looking through mroute.c, I find
mroute_get_in_addr_t(struct mroute_addr *out, const in_addr_t in, int mask)
which should do the same with less lines of intermediate structure filling :-) (have not tested this, just compared code)
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/8290fc03_3b80051e?usp=email :
PS3, Line 4339:mroute_get_in6_addr(&addr, a6, 0) does this for you
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/cbc56eb6_41bab12b?usp=email :
PS3, Line 4366: old_addr.s_addr = ntohl(mi->context.c2.push_ifconfig_local);
we could just do in_addr_t old_addr = ... here and save the detour via struct in_addr?
File src/openvpn/push_util.c:
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/07ab8769_ed9bfa83?usp=email :
PS3, Line 158: memset(&o, 0, sizeof(struct options));
please use CLEAR(o); for that. It does exactly the same, but we use it in this situation so it's clear "this is not just a random memset() but to 0-initialize the options struct".
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 3
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Sun, 12 Oct 2025 11:18:28 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: cron2, flichtenheld, mrbff, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
to look at the new patch set (#4).
The following approvals got outdated and were removed:
Code-Review-1 by cron2
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
When sending a PUSH_UPDATE containing an ifconfig(-ipv6) option, we must add the new IP to the multi_context vhash (hash table of the clients indexed by virtual IPs). Now in addition to adding new client IPs, old IPs are also removed from vhash, allowing for a more complete update.
---
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/push_util.c
M tests/unit_tests/openvpn/test_push_update_msg.c
6 files changed, 151 insertions(+), 72 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/53/1253/4
src/openvpn/multi.c +117 -29
@@ -4269,46 +4269,134 @@close_instance (top); } +/* Searches for the address and deletes it if it is owned by the multi_instance */ +static void +multi_unlearn_addr (struct multi_context *m,struct multi_instance *mi,const struct mroute_addr *addr) +{ +struct hash_element *he; +const uint32_t hv =hash_value (m->vhash, addr); +struct hash_bucket *bucket =hash_bucket (m->vhash, hv); +struct multi_route *r =NULL ; + +/* if route currently exists, get the instance which owns it */ + he =hash_lookup_fast (m->vhash, bucket, addr, hv); +if (he) + { + r = (struct multi_route *)he->value; + } + +/* if the route does not exist or exists but is not owned by the current instance, return */ +if (!r || r->instance != mi) + { +return ; + } + +struct gc_arena gc =gc_new (); +set_prefix (mi); +msg (D_MULTI_LOW ,"MULTI: multi_unlearn_addr(): DEL %s" ,mroute_addr_print (&r->addr, &gc)); +clear_prefix (); +learn_address_script (m,NULL ,"delete" , &r->addr); +hash_remove_by_value (m->vhash, r); +multi_route_del (r); + +gc_free (&gc); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a The new IPv4 address in host byte order +*/ +static void +multi_unlearn_in_addr_t (struct multi_context *m,struct multi_instance *mi,in_addr_t a) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV4 ; + addr.len =4 ; + addr.v4.addr = a; + +multi_unlearn_addr (m, mi, &addr); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a6 The new IPv6 address in host byte order +*/ +static void +multi_unlearn_in6_addr (struct multi_context *m,struct multi_instance *mi,struct in6_addr a6) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV6 ; + addr.len =16 ; + addr.v6.addr = a6; + +multi_unlearn_addr (m, mi, &addr); +} +/** * Update the vhash with new IP/IPv6 addresses in the multi_context when a * push-update message containing ifconfig/ifconfig-ipv6 options is sent -* from the server. This function should be called after a push-update -* and old_ip/old_ipv6 are the previous addresses of the client in -* ctx->options.ifconfig_local and ctx->options.ifconfig_ipv6_local. +* from the server. +* +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param new_ip The new IPv4 address or NULL if no change +* @param new_ipv6 The new IPv6 address or NULL if no change */ void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) { -struct in_addr addr; -struct in6_addr new_ipv6; - -if ((mi->context.options.ifconfig_local && (!old_ip ||strcmp (old_ip, mi->context.options.ifconfig_local))) - &&inet_pton (AF_INET , mi->context.options.ifconfig_local, &addr) ==1 ) +if (new_ip) { -in_addr_t new_ip =ntohl (addr.s_addr); +in_addr_t old_addr =0 ; +struct in_addr new_addr; +CLEAR (new_addr); + +/* Remove old IP */ +if (mi->context.c2.push_ifconfig_defined) + { + old_addr =ntohl (mi->context.c2.push_ifconfig_local); +multi_unlearn_in_addr_t (m, mi, old_addr); + mi->context.c2.push_ifconfig_defined = false; + mi->context.c2.push_ifconfig_local =0 ; + }/* Add new IP */ -multi_learn_in_addr_t (m, mi, new_ip,-1 , true); +if (inet_pton (AF_INET , new_ip, &new_addr) ==1 + &&multi_learn_in_addr_t (m, mi,ntohl (new_addr.s_addr),-1 , true)) + { + mi->context.c2.push_ifconfig_defined = true; + mi->context.c2.push_ifconfig_local = new_addr.s_addr; + } } -/* TO DO: -* else if (old_ip) -* { -* // remove old IP -* } -*/ - -if ((mi->context.options.ifconfig_ipv6_local && (!old_ipv6 ||strcmp (old_ipv6, mi->context.options.ifconfig_ipv6_local))) - &&inet_pton (AF_INET6 , mi->context.options.ifconfig_ipv6_local, &new_ipv6) ==1 ) +if (new_ipv6) { -/* Add new IPv6 */ -multi_learn_in6_addr (m, mi, new_ipv6,-1 , true); - } +struct in6_addr new_addr6; +struct in6_addr old_addr6; +CLEAR (new_addr6); +CLEAR (old_addr6); -/* TO DO: -* else if (old_ipv6) -* { -* // remove old IPv6 -* } -*/ +/* Remove old IPv6 */ +if (mi->context.c2.push_ifconfig_ipv6_defined) + { + old_addr6 = mi->context.c2.push_ifconfig_ipv6_local; +multi_unlearn_in6_addr (m, mi, old_addr6); + mi->context.c2.push_ifconfig_ipv6_defined = false; +CLEAR (mi->context.c2.push_ifconfig_ipv6_local); + } + +/* Add new IPv6 */ +if (inet_pton (AF_INET6 , new_ipv6, &new_addr6) ==1 + &&multi_learn_in6_addr (m, mi, new_addr6,-1 , true)) + { + mi->context.c2.push_ifconfig_ipv6_defined = true; + mi->context.c2.push_ifconfig_ipv6_local = new_addr6; + } + } }
src/openvpn/multi.h +1 -1
@@ -692,6 +692,6 @@#endif void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6); +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6);#endif /* MULTI_H */
src/openvpn/push.c +1 -1
@@ -1118,7 +1118,7 @@ " To be able to process PUSH_UPDATE messages, be sure to use the --disable-dco option.");return PUSH_MSG_ERROR ; } -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
src/openvpn/push.h +5 -4
@@ -61,11 +61,13 @@* message has not yet been received. * * @param c The context for the operation. +* @param o The options structure to be updated with the received push options. * @param permission_mask The permission mask specifying which options are allowed to be pulled. * @param option_types_found A pointer to a variable that will be filled with the types of options * found in the message. * @param buf A buffer containing the received message. -* @param msg_sender A boolean indicating if function is called by the message sender (server). +* @param msg_sender A boolean indicating if the message is being processed on the client (false) +* or on the server (true). * * @return * - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied.
@@ -74,9 +76,8 @@* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. */ -int process_incoming_push_update (struct context *c,unsigned int permission_mask, -unsigned int *option_types_found,struct buffer *buf, -bool msg_sender); +int process_push_update (struct context *c,struct options *o,unsigned int permission_mask, +unsigned int *option_types_found,struct buffer *buf,bool msg_sender); int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options, unsigned int permission_mask,
src/openvpn/push_util.c +25 -35
128 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +2 -2
@@ -29,7 +29,7 @@ }void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) {return ; }
@@ -95,7 +95,7 @@ }else if (honor_received_options &&buf_string_compare_advance (&buf, push_update_cmd)) { -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 4
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Attention is currently required from: cron2, flichtenheld, plaisthos.
mrbff has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email )
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
Patch Set 4:
(6 comments)
File src/openvpn/multi.c:
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/669873c8_f711dc79?usp=email :
PS3, Line 4296: msg(D_MULTI_LOW, "MULTI: Remove: %s -> %s", mroute_addr_print(&r->addr, &gc), multi_instance_string(mi, false, &gc));
Quoted 1 line
this is too much logging ;-) […]
Done
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/94ace8fa_436f6223?usp=email :
PS3, Line 4301:
Quoted 1 line
we might have a memleak here. I looked at the code in "multi. […]
Done
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/cf4e61f7_f768ee6d?usp=email :
PS3, Line 4320: ASSERT(mroute_extract_openvpn_sockaddr(&addr, &remote_si, false));
Quoted 1 line
This works, but feels more clumsy than needed - looking through
mroute.c, I find […]
mroute_get_in_addr_t() and mroute_get_in6_add6() are a static inline (and i suppose there is a reason for that, but even if not, why bother), anyway i got your point and i tried to make the helper less clumsy and more symmetric.
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/cec62582_b1eddb2e?usp=email :
PS3, Line 4339:
Quoted 1 line
mroute_get_in6_addr(&addr, a6, 0)does this for you
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/5bac7178_9e782090?usp=email :
PS3, Line 4366: old_addr.s_addr = ntohl(mi->context.c2.push_ifconfig_local);
Quoted 1 line
we could just do `in_addr_t
old_addr= ... […]
Done
File src/openvpn/push_util.c:
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/79224a68_ad59ff25?usp=email :
PS3, Line 158: memset(&o, 0, sizeof(struct options));
Quoted 1 line
please use
CLEAR(o);for that. […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 4
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 13 Oct 2025 08:59:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Attention is currently required from: flichtenheld, mrbff, plaisthos.
cron2 has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email )
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
Patch Set 4: Code-Review+2
(1 comment)
File src/openvpn/multi.c:
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/08a5a1e5_12b1e3b5?usp=email :
PS3, Line 4320: ASSERT(mroute_extract_openvpn_sockaddr(&addr, &remote_si, false));
Quoted 1 line
mroute_get_in_addr_t()andmroute_get_in6_add6()are a static inline (and i suppose there is a reaso […]
Ah, how annoying. Didn't notice the static inline. Yeah, it's only used inside mroute.c today - we could export it, or make it non-inline, but this would make the scope of the patch much larger.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 4
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Mon, 13 Oct 2025 09:19:25 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: cron2 <[email protected]...>
Comment-In-Reply-To: mrbff <[email protected]...>
PATCH v4 1/1 PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
In reply to a message not in the archiveFrom: Marco Baffo <[email protected]...>
When sending a PUSH_UPDATE containing an ifconfig(-ipv6) option, we must add the new IP to the multi_context vhash (hash table of the clients indexed by virtual IPs). Now in addition to adding new client IPs, old IPs are also removed from vhash, allowing for a more complete update.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1253
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1253
This mail reflects revision 4 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
src/openvpn/multi.c +117 -29
@@ -4269,46 +4269,134 @@close_instance (top); } +/* Searches for the address and deletes it if it is owned by the multi_instance */ +static void +multi_unlearn_addr (struct multi_context *m,struct multi_instance *mi,const struct mroute_addr *addr) +{ +struct hash_element *he; +const uint32_t hv =hash_value (m->vhash, addr); +struct hash_bucket *bucket =hash_bucket (m->vhash, hv); +struct multi_route *r =NULL ; + +/* if route currently exists, get the instance which owns it */ + he =hash_lookup_fast (m->vhash, bucket, addr, hv); +if (he) + { + r = (struct multi_route *)he->value; + } + +/* if the route does not exist or exists but is not owned by the current instance, return */ +if (!r || r->instance != mi) + { +return ; + } + +struct gc_arena gc =gc_new (); +set_prefix (mi); +msg (D_MULTI_LOW ,"MULTI: multi_unlearn_addr(): DEL %s" ,mroute_addr_print (&r->addr, &gc)); +clear_prefix (); +learn_address_script (m,NULL ,"delete" , &r->addr); +hash_remove_by_value (m->vhash, r); +multi_route_del (r); + +gc_free (&gc); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a The new IPv4 address in host byte order +*/ +static void +multi_unlearn_in_addr_t (struct multi_context *m,struct multi_instance *mi,in_addr_t a) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV4 ; + addr.len =4 ; + addr.v4.addr = a; + +multi_unlearn_addr (m, mi, &addr); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a6 The new IPv6 address in host byte order +*/ +static void +multi_unlearn_in6_addr (struct multi_context *m,struct multi_instance *mi,struct in6_addr a6) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV6 ; + addr.len =16 ; + addr.v6.addr = a6; + +multi_unlearn_addr (m, mi, &addr); +} +/** * Update the vhash with new IP/IPv6 addresses in the multi_context when a * push-update message containing ifconfig/ifconfig-ipv6 options is sent -* from the server. This function should be called after a push-update -* and old_ip/old_ipv6 are the previous addresses of the client in -* ctx->options.ifconfig_local and ctx->options.ifconfig_ipv6_local. +* from the server. +* +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param new_ip The new IPv4 address or NULL if no change +* @param new_ipv6 The new IPv6 address or NULL if no change */ void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) { -struct in_addr addr; -struct in6_addr new_ipv6; - -if ((mi->context.options.ifconfig_local && (!old_ip ||strcmp (old_ip, mi->context.options.ifconfig_local))) - &&inet_pton (AF_INET , mi->context.options.ifconfig_local, &addr) ==1 ) +if (new_ip) { -in_addr_t new_ip =ntohl (addr.s_addr); +in_addr_t old_addr =0 ; +struct in_addr new_addr; +CLEAR (new_addr); + +/* Remove old IP */ +if (mi->context.c2.push_ifconfig_defined) + { + old_addr =ntohl (mi->context.c2.push_ifconfig_local); +multi_unlearn_in_addr_t (m, mi, old_addr); + mi->context.c2.push_ifconfig_defined = false; + mi->context.c2.push_ifconfig_local =0 ; + }/* Add new IP */ -multi_learn_in_addr_t (m, mi, new_ip,-1 , true); +if (inet_pton (AF_INET , new_ip, &new_addr) ==1 + &&multi_learn_in_addr_t (m, mi,ntohl (new_addr.s_addr),-1 , true)) + { + mi->context.c2.push_ifconfig_defined = true; + mi->context.c2.push_ifconfig_local = new_addr.s_addr; + } } -/* TO DO: -* else if (old_ip) -* { -* // remove old IP -* } -*/ - -if ((mi->context.options.ifconfig_ipv6_local && (!old_ipv6 ||strcmp (old_ipv6, mi->context.options.ifconfig_ipv6_local))) - &&inet_pton (AF_INET6 , mi->context.options.ifconfig_ipv6_local, &new_ipv6) ==1 ) +if (new_ipv6) { -/* Add new IPv6 */ -multi_learn_in6_addr (m, mi, new_ipv6,-1 , true); - } +struct in6_addr new_addr6; +struct in6_addr old_addr6; +CLEAR (new_addr6); +CLEAR (old_addr6); -/* TO DO: -* else if (old_ipv6) -* { -* // remove old IPv6 -* } -*/ +/* Remove old IPv6 */ +if (mi->context.c2.push_ifconfig_ipv6_defined) + { + old_addr6 = mi->context.c2.push_ifconfig_ipv6_local; +multi_unlearn_in6_addr (m, mi, old_addr6); + mi->context.c2.push_ifconfig_ipv6_defined = false; +CLEAR (mi->context.c2.push_ifconfig_ipv6_local); + } + +/* Add new IPv6 */ +if (inet_pton (AF_INET6 , new_ipv6, &new_addr6) ==1 + &&multi_learn_in6_addr (m, mi, new_addr6,-1 , true)) + { + mi->context.c2.push_ifconfig_ipv6_defined = true; + mi->context.c2.push_ifconfig_ipv6_local = new_addr6; + } + } }
src/openvpn/multi.h +1 -1
@@ -692,6 +692,6 @@#endif void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6); +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6);#endif /* MULTI_H */
src/openvpn/push.c +1 -1
@@ -1118,7 +1118,7 @@ " To be able to process PUSH_UPDATE messages, be sure to use the --disable-dco option.");return PUSH_MSG_ERROR ; } -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
src/openvpn/push.h +5 -4
@@ -61,11 +61,13 @@* message has not yet been received. * * @param c The context for the operation. +* @param o The options structure to be updated with the received push options. * @param permission_mask The permission mask specifying which options are allowed to be pulled. * @param option_types_found A pointer to a variable that will be filled with the types of options * found in the message. * @param buf A buffer containing the received message. -* @param msg_sender A boolean indicating if function is called by the message sender (server). +* @param msg_sender A boolean indicating if the message is being processed on the client (false) +* or on the server (true). * * @return * - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied.
@@ -74,9 +76,8 @@* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. */ -int process_incoming_push_update (struct context *c,unsigned int permission_mask, -unsigned int *option_types_found,struct buffer *buf, -bool msg_sender); +int process_push_update (struct context *c,struct options *o,unsigned int permission_mask, +unsigned int *option_types_found,struct buffer *buf,bool msg_sender); int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options, unsigned int permission_mask,
src/openvpn/push_util.c +25 -35
128 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +2 -2
@@ -29,7 +29,7 @@ }void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) {return ; }
@@ -95,7 +95,7 @@ }else if (honor_received_options &&buf_string_compare_advance (&buf, push_update_cmd)) { -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
Attention is currently required from: flichtenheld, mrbff, plaisthos.
cron2 has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email )
The change is no longer submittable: Code-Review is unsatisfied now.
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
Patch Set 4: Code-Review-1
(1 comment)
Patchset:
PS4:
Aaaah, partly there.
So, the *first* "PUSH_UPDATE,ifconfig..." works as expected
- new IP address is pinging
- old IP address is logged as "unlearn_addr()"
- packets for new IP are sent to the client, packets for old IP are no longer sent (verified with tcpdump on the client tun)
This works for both IPv4 and IPv6.
Then, another "PUSH_UPDATE,ifconfig..." and it correctly learns the "new new" IP address, but does not unlearn the second address, and tcpdump shows packets for 2 IPs arrive (.99 is the "first PUSH_UPDATE", .146 is the "second PUSH_UPDATE")
``` 12:39:48.791099 IP 10.204.2.1 > 10.204.2.99: ICMP echo request, id 50521, seq 90, length 64 12:39:48.791109 IP 10.204.2.1 > 10.204.2.99: ICMP echo request, id 50521, seq 90, length 64 12:39:48.791122 IP 10.204.2.1 > 10.204.2.146: ICMP echo request, id 64784, seq 90, length 64 ```
packets are logged twice because the client has routing enabled and just sends the packet back (the server will then log MULTI: bad source address from client [10.204.2.1], packet dropped).
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 4
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Mon, 13 Oct 2025 10:42:09 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: cron2, flichtenheld, mrbff, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
to look at the new patch set (#5).
The following approvals got outdated and were removed:
Code-Review-1 by cron2
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
When sending a PUSH_UPDATE containing an ifconfig(-ipv6) option, we must add the new IP to the multi_context vhash (hash table of the clients indexed by virtual IPs). Now in addition to adding new client IPs, old IPs are also removed from vhash, allowing for a more complete update.
---
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/push_util.c
M tests/unit_tests/openvpn/test_push_update_msg.c
6 files changed, 203 insertions(+), 72 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/53/1253/5
src/openvpn/multi.c +127 -29
@@ -4269,46 +4269,144 @@close_instance (top); } +/* Searches for the address and deletes it if it is owned by the multi_instance */ +static void +multi_unlearn_addr (struct multi_context *m,struct multi_instance *mi,const struct mroute_addr *addr) +{ +struct hash_element *he; +const uint32_t hv =hash_value (m->vhash, addr); +struct hash_bucket *bucket =hash_bucket (m->vhash, hv); +struct multi_route *r =NULL ; + +/* if route currently exists, get the instance which owns it */ + he =hash_lookup_fast (m->vhash, bucket, addr, hv); +if (he) + { + r = (struct multi_route *)he->value; + } + +/* if the route does not exist or exists but is not owned by the current instance, return */ +if (!r || r->instance != mi) + { +return ; + } + +struct gc_arena gc =gc_new (); +msg (D_MULTI_LOW ,"MULTI: Unlearn: %s -> %s" ,mroute_addr_print (&r->addr, &gc),multi_instance_string (mi, false, &gc)); +learn_address_script (m,NULL ,"delete" , &r->addr); +hash_remove_by_value (m->vhash, r); +multi_route_del (r); + +gc_free (&gc); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a The new IPv4 address in host byte order +*/ +static void +multi_unlearn_in_addr_t (struct multi_context *m,struct multi_instance *mi,in_addr_t a) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV4 ; + addr.len =4 ; + addr.v4.addr = a; + +multi_unlearn_addr (m, mi, &addr); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a6 The new IPv6 address in host byte order +*/ +static void +multi_unlearn_in6_addr (struct multi_context *m,struct multi_instance *mi,struct in6_addr a6) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV6 ; + addr.len =16 ; + addr.v6.addr = a6; + +multi_unlearn_addr (m, mi, &addr); +} + +/* Function to unlearn previous ifconfig of a client in the server multi_context after a PUSH_UPDATE */ +void +unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi) +{ +in_addr_t old_addr =0 ; + old_addr =ntohl (mi->context.c2.push_ifconfig_local); +multi_unlearn_in_addr_t (m, mi, old_addr); + mi->context.c2.push_ifconfig_defined = false; + mi->context.c2.push_ifconfig_local =0 ; +} + +/* Function to unlearn previous ifconfig-ipv6 of a client in the server multi_context after a PUSH_UPDATE */ +void +unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi) +{ +struct in6_addr old_addr6; +CLEAR (old_addr6); + old_addr6 = mi->context.c2.push_ifconfig_ipv6_local; +multi_unlearn_in6_addr (m, mi, old_addr6); + mi->context.c2.push_ifconfig_ipv6_defined = false; +CLEAR (mi->context.c2.push_ifconfig_ipv6_local); +} +/** * Update the vhash with new IP/IPv6 addresses in the multi_context when a * push-update message containing ifconfig/ifconfig-ipv6 options is sent -* from the server. This function should be called after a push-update -* and old_ip/old_ipv6 are the previous addresses of the client in -* ctx->options.ifconfig_local and ctx->options.ifconfig_ipv6_local. +* from the server. +* +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param new_ip The new IPv4 address or NULL if no change +* @param new_ipv6 The new IPv6 address or NULL if no change */ void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) { -struct in_addr addr; -struct in6_addr new_ipv6; - -if ((mi->context.options.ifconfig_local && (!old_ip ||strcmp (old_ip, mi->context.options.ifconfig_local))) - &&inet_pton (AF_INET , mi->context.options.ifconfig_local, &addr) ==1 ) +if (new_ip) { -in_addr_t new_ip =ntohl (addr.s_addr); +/* Remove old IP */ +if (mi->context.c2.push_ifconfig_defined) + { +unlearn_ifconfig (m, mi); + }/* Add new IP */ -multi_learn_in_addr_t (m, mi, new_ip,-1 , true); +struct in_addr new_addr; +CLEAR (new_addr); +if (inet_pton (AF_INET , new_ip, &new_addr) ==1 + &&multi_learn_in_addr_t (m, mi,ntohl (new_addr.s_addr),-1 , true)) + { + mi->context.c2.push_ifconfig_defined = true; + mi->context.c2.push_ifconfig_local =htonl (new_addr.s_addr); + } } -/* TO DO: -* else if (old_ip) -* { -* // remove old IP -* } -*/ - -if ((mi->context.options.ifconfig_ipv6_local && (!old_ipv6 ||strcmp (old_ipv6, mi->context.options.ifconfig_ipv6_local))) - &&inet_pton (AF_INET6 , mi->context.options.ifconfig_ipv6_local, &new_ipv6) ==1 ) +if (new_ipv6) { -/* Add new IPv6 */ -multi_learn_in6_addr (m, mi, new_ipv6,-1 , true); - } +/* Remove old IPv6 */ +if (mi->context.c2.push_ifconfig_ipv6_defined) + { +unlearn_ifconfig_ipv6 (m, mi); + } -/* TO DO: -* else if (old_ipv6) -* { -* // remove old IPv6 -* } -*/ +/* Add new IPv6 */ +struct in6_addr new_addr6; +CLEAR (new_addr6); +if (inet_pton (AF_INET6 , new_ipv6, &new_addr6) ==1 + &&multi_learn_in6_addr (m, mi, new_addr6,-1 , true)) + { + mi->context.c2.push_ifconfig_ipv6_defined = true; + mi->context.c2.push_ifconfig_ipv6_local = new_addr6; + } + } }
src/openvpn/multi.h +3 -1
@@ -692,6 +692,8 @@#endif void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6); +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6); +void unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi); +void unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi);#endif /* MULTI_H */
src/openvpn/push.c +1 -1
@@ -1118,7 +1118,7 @@ " To be able to process PUSH_UPDATE messages, be sure to use the --disable-dco option.");return PUSH_MSG_ERROR ; } -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
src/openvpn/push.h +5 -4
@@ -61,11 +61,13 @@* message has not yet been received. * * @param c The context for the operation. +* @param o The options structure to be updated with the received push options. * @param permission_mask The permission mask specifying which options are allowed to be pulled. * @param option_types_found A pointer to a variable that will be filled with the types of options * found in the message. * @param buf A buffer containing the received message. -* @param msg_sender A boolean indicating if function is called by the message sender (server). +* @param msg_sender A boolean indicating if the message is being processed on the client (false) +* or on the server (true). * * @return * - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied.
@@ -74,9 +76,8 @@* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. */ -int process_incoming_push_update (struct context *c,unsigned int permission_mask, -unsigned int *option_types_found,struct buffer *buf, -bool msg_sender); +int process_push_update (struct context *c,struct options *o,unsigned int permission_mask, +unsigned int *option_types_found,struct buffer *buf,bool msg_sender); int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options, unsigned int permission_mask,
src/openvpn/push_util.c +53 -35
156 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +14 -2
@@ -29,7 +29,19 @@ }void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi) +{ +return ; +} + +void +unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi) +{ +return ; +} + +void +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) {return ; }
@@ -95,7 +107,7 @@ }else if (honor_received_options &&buf_string_compare_advance (&buf, push_update_cmd)) { -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 5
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Attention is currently required from: cron2, flichtenheld, plaisthos.
mrbff has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email )
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
Patch Set 4:
(1 comment)
Patchset:
PS4:
Quoted 1 line
Aaaah, partly there. […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 4
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 13 Oct 2025 13:19:59 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Attention is currently required from: cron2, flichtenheld, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
to look at the new patch set (#6).
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
When sending a PUSH_UPDATE containing an ifconfig(-ipv6) option, we must add the new IP to the multi_context vhash (hash table of the clients indexed by virtual IPs). Now in addition to adding new client IPs, old IPs are also removed from vhash, allowing for a more complete update.
---
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/push_util.c
M tests/unit_tests/openvpn/test_push_update_msg.c
6 files changed, 205 insertions(+), 72 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/53/1253/6
src/openvpn/multi.c +127 -29
@@ -4269,46 +4269,144 @@close_instance (top); } +/* Searches for the address and deletes it if it is owned by the multi_instance */ +static void +multi_unlearn_addr (struct multi_context *m,struct multi_instance *mi,const struct mroute_addr *addr) +{ +struct hash_element *he; +const uint32_t hv =hash_value (m->vhash, addr); +struct hash_bucket *bucket =hash_bucket (m->vhash, hv); +struct multi_route *r =NULL ; + +/* if route currently exists, get the instance which owns it */ + he =hash_lookup_fast (m->vhash, bucket, addr, hv); +if (he) + { + r = (struct multi_route *)he->value; + } + +/* if the route does not exist or exists but is not owned by the current instance, return */ +if (!r || r->instance != mi) + { +return ; + } + +struct gc_arena gc =gc_new (); +msg (D_MULTI_LOW ,"MULTI: Unlearn: %s -> %s" ,mroute_addr_print (&r->addr, &gc),multi_instance_string (mi, false, &gc)); +learn_address_script (m,NULL ,"delete" , &r->addr); +hash_remove_by_value (m->vhash, r); +multi_route_del (r); + +gc_free (&gc); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a The new IPv4 address in host byte order +*/ +static void +multi_unlearn_in_addr_t (struct multi_context *m,struct multi_instance *mi,in_addr_t a) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV4 ; + addr.len =4 ; + addr.v4.addr = a; + +multi_unlearn_addr (m, mi, &addr); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a6 The new IPv6 address in host byte order +*/ +static void +multi_unlearn_in6_addr (struct multi_context *m,struct multi_instance *mi,struct in6_addr a6) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV6 ; + addr.len =16 ; + addr.v6.addr = a6; + +multi_unlearn_addr (m, mi, &addr); +} + +/* Function to unlearn previous ifconfig of a client in the server multi_context after a PUSH_UPDATE */ +void +unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi) +{ +in_addr_t old_addr =0 ; + old_addr =ntohl (mi->context.c2.push_ifconfig_local); +multi_unlearn_in_addr_t (m, mi, old_addr); + mi->context.c2.push_ifconfig_defined = false; + mi->context.c2.push_ifconfig_local =0 ; +} + +/* Function to unlearn previous ifconfig-ipv6 of a client in the server multi_context after a PUSH_UPDATE */ +void +unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi) +{ +struct in6_addr old_addr6; +CLEAR (old_addr6); + old_addr6 = mi->context.c2.push_ifconfig_ipv6_local; +multi_unlearn_in6_addr (m, mi, old_addr6); + mi->context.c2.push_ifconfig_ipv6_defined = false; +CLEAR (mi->context.c2.push_ifconfig_ipv6_local); +} +/** * Update the vhash with new IP/IPv6 addresses in the multi_context when a * push-update message containing ifconfig/ifconfig-ipv6 options is sent -* from the server. This function should be called after a push-update -* and old_ip/old_ipv6 are the previous addresses of the client in -* ctx->options.ifconfig_local and ctx->options.ifconfig_ipv6_local. +* from the server. +* +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param new_ip The new IPv4 address or NULL if no change +* @param new_ipv6 The new IPv6 address or NULL if no change */ void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) { -struct in_addr addr; -struct in6_addr new_ipv6; - -if ((mi->context.options.ifconfig_local && (!old_ip ||strcmp (old_ip, mi->context.options.ifconfig_local))) - &&inet_pton (AF_INET , mi->context.options.ifconfig_local, &addr) ==1 ) +if (new_ip) { -in_addr_t new_ip =ntohl (addr.s_addr); +/* Remove old IP */ +if (mi->context.c2.push_ifconfig_defined) + { +unlearn_ifconfig (m, mi); + }/* Add new IP */ -multi_learn_in_addr_t (m, mi, new_ip,-1 , true); +struct in_addr new_addr; +CLEAR (new_addr); +if (inet_pton (AF_INET , new_ip, &new_addr) ==1 + &&multi_learn_in_addr_t (m, mi,ntohl (new_addr.s_addr),-1 , true)) + { + mi->context.c2.push_ifconfig_defined = true; + mi->context.c2.push_ifconfig_local =htonl (new_addr.s_addr); + } } -/* TO DO: -* else if (old_ip) -* { -* // remove old IP -* } -*/ - -if ((mi->context.options.ifconfig_ipv6_local && (!old_ipv6 ||strcmp (old_ipv6, mi->context.options.ifconfig_ipv6_local))) - &&inet_pton (AF_INET6 , mi->context.options.ifconfig_ipv6_local, &new_ipv6) ==1 ) +if (new_ipv6) { -/* Add new IPv6 */ -multi_learn_in6_addr (m, mi, new_ipv6,-1 , true); - } +/* Remove old IPv6 */ +if (mi->context.c2.push_ifconfig_ipv6_defined) + { +unlearn_ifconfig_ipv6 (m, mi); + } -/* TO DO: -* else if (old_ipv6) -* { -* // remove old IPv6 -* } -*/ +/* Add new IPv6 */ +struct in6_addr new_addr6; +CLEAR (new_addr6); +if (inet_pton (AF_INET6 , new_ipv6, &new_addr6) ==1 + &&multi_learn_in6_addr (m, mi, new_addr6,-1 , true)) + { + mi->context.c2.push_ifconfig_ipv6_defined = true; + mi->context.c2.push_ifconfig_ipv6_local = new_addr6; + } + } }
src/openvpn/multi.h +3 -1
@@ -692,6 +692,8 @@#endif void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6); +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6); +void unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi); +void unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi);#endif /* MULTI_H */
src/openvpn/push.c +1 -1
@@ -1118,7 +1118,7 @@ " To be able to process PUSH_UPDATE messages, be sure to use the --disable-dco option.");return PUSH_MSG_ERROR ; } -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
src/openvpn/push.h +5 -4
@@ -61,11 +61,13 @@* message has not yet been received. * * @param c The context for the operation. +* @param o The options structure to be updated with the received push options. * @param permission_mask The permission mask specifying which options are allowed to be pulled. * @param option_types_found A pointer to a variable that will be filled with the types of options * found in the message. * @param buf A buffer containing the received message. -* @param msg_sender A boolean indicating if function is called by the message sender (server). +* @param msg_sender A boolean indicating if the message is being processed on the client (false) +* or on the server (true). * * @return * - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied.
@@ -74,9 +76,8 @@* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. */ -int process_incoming_push_update (struct context *c,unsigned int permission_mask, -unsigned int *option_types_found,struct buffer *buf, -bool msg_sender); +int process_push_update (struct context *c,struct options *o,unsigned int permission_mask, +unsigned int *option_types_found,struct buffer *buf,bool msg_sender); int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options, unsigned int permission_mask,
src/openvpn/push_util.c +55 -35
158 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +14 -2
@@ -29,7 +29,19 @@ }void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi) +{ +return ; +} + +void +unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi) +{ +return ; +} + +void +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) {return ; }
@@ -95,7 +107,7 @@ }else if (honor_received_options &&buf_string_compare_advance (&buf, push_update_cmd)) { -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 6
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Attention is currently required from: cron2, flichtenheld, mrbff, plaisthos.
ordex has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email )
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
Patch Set 6:
(2 comments)
File src/openvpn/push_util.c:
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/ffcc2b41_1a82ecae?usp=email :
PS6, Line 165: o.ifconfig_local = canary;
in other parts of the code we use having a bool named like $option_defined (in this case it would be o.ifconfig_local_defined) which is set to true when the option is present, but the value is ambiguous.
May it make sense to do the same here instead of going the "canary" logic which would be unique to this piece of code?
@[email protected]... any opinion?
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/fdd76947_101b92fc?usp=email :
PS6, Line 166: o.ifconfig_ipv6_local = canary;
same for this obviously.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 6
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Tue, 14 Oct 2025 12:31:29 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Attention is currently required from: cron2, flichtenheld, mrbff, plaisthos.
ordex has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email )
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
Patch Set 6:
(1 comment)
File src/openvpn/multi.c:
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/88c29763_372fcfb0?usp=email :
PS5, Line 4390: mi->context.c2.push_ifconfig_local = htonl(new_addr.s_addr);
something is weird here. if we are calling ntohl(s_addr) a few lines above, we can't just call htonl(s_addr) here.... @[email protected]... you said you printed the values *byte by byte*?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 6
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Tue, 14 Oct 2025 12:36:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Attention is currently required from: cron2, flichtenheld, ordex, plaisthos.
mrbff has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email )
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
Patch Set 6:
(2 comments)
File src/openvpn/multi.c:
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/fc5a283e_68bf4b30?usp=email :
PS5, Line 4390: mi->context.c2.push_ifconfig_local = htonl(new_addr.s_addr);
Quoted 1 line
something is weird here. […]
yes I printed bit by bit and they are the same and I don't understand why htonl fixes things and I don't understand why (addr.s_addr == htonl(add.s_addr)) statement is false.
uint32
2025-10-14 17:40:06 us=422285 MANAGEMENT: CMD 'push-update-cid 0 "ifconfig 10.10.10.55 255.255.255.0"' 2025-10-14 17:40:06 us=422386 SENT CONTROL [client0]: 'PUSH_UPDATE,ifconfig 10.10.10.55 255.255.255.0' (status=1) 2025-10-14 17:40:06 us=422409 MULTI: Unlearn: 10.10.10.2 -> client0/udp6:92.168.3.1:37467 2025-10-14 17:40:06 us=422422 MULTI: Learn: 10.10.10.55 -> client0/udp6:92.168.3.1:37467
2025-10-14 17:40:06 us=422432 New IPv4 Address Analysis: 2025-10-14 17:40:06 us=422437 Original s_addr: 0x370a0a0a = 923404810 = 00110111000010100000101000001010 2025-10-14 17:40:06 us=422442 ntohl(s_addr): 0x0a0a0a37 = 168430135 = 00001010000010100000101000110111 2025-10-14 17:40:06 us=422448 htonl(s_addr): 0x0a0a0a37 = 168430135 = 00001010000010100000101000110111 2025-10-14 17:40:06 us=422454 As IP address: 10.10.10.55
uint64
2025-10-14 17:49:28 us=407391 MANAGEMENT: CMD 'push-update-cid 0 "ifconfig 10.10.10.55 255.255.255.0"' 2025-10-14 17:49:28 us=407531 SENT CONTROL [client0]: 'PUSH_UPDATE,ifconfig 10.10.10.55 255.255.255.0' (status=1) 2025-10-14 17:49:28 us=407565 MULTI: Unlearn: 10.10.10.2 -> client0/udp6:92.168.3.1:37923 2025-10-14 17:49:28 us=407581 MULTI: Learn: 10.10.10.55 -> client0/udp6:92.168.3.1:37923
2025-10-14 17:49:28 us=407592 New IPv4 Address Analysis: 2025-10-14 17:49:28 us=407600 Original s_addr: 0x370a0a0a = 923404810 = 0000000000000000000000000000000000110111000010100000101000001010 2025-10-14 17:49:28 us=407606 ntohl(s_addr): 0x0a0a0a37 = 168430135 = 0000000000000000000000000000000000001010000010100000101000110111 2025-10-14 17:49:28 us=407613 htonl(s_addr): 0x0a0a0a37 = 168430135 = 0000000000000000000000000000000000001010000010100000101000110111 2025-10-14 17:49:28 us=407619 As IP address: 10.10.10.55
File src/openvpn/push_util.c:
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/bd5cee56_ee31112f?usp=email :
PS6, Line 165: o.ifconfig_local = canary;
Quoted 1 line
in other parts of the code we use having a bool named like
$option_defined(in this case it would […]
the canary is mostly to be less invasive as possible. I know it's a bit weird but it works well and minimizes the scope for this logic without having to touch other functions that are also used in other parts of the code in different logic. Adding ifconfig_local_defined to the options struct and modifying add_option() and remove_option(), just to handle -ifconfig(-ipv6) in the server looks a little overkill to me.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 6
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Tue, 14 Oct 2025 16:05:02 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: ordex <[email protected]...>
Attention is currently required from: cron2, flichtenheld, ordex, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
to look at the new patch set (#7).
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
When sending a PUSH_UPDATE containing an ifconfig(-ipv6) option, we must add the new IP to the multi_context vhash (hash table of the clients indexed by virtual IPs). Now in addition to adding new client IPs, old IPs are also removed from vhash, allowing for a more complete update.
---
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/push_util.c
M tests/unit_tests/openvpn/test_push_update_msg.c
6 files changed, 205 insertions(+), 72 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/53/1253/7
src/openvpn/multi.c +127 -29
@@ -4269,46 +4269,144 @@close_instance (top); } +/* Searches for the address and deletes it if it is owned by the multi_instance */ +static void +multi_unlearn_addr (struct multi_context *m,struct multi_instance *mi,const struct mroute_addr *addr) +{ +struct hash_element *he; +const uint32_t hv =hash_value (m->vhash, addr); +struct hash_bucket *bucket =hash_bucket (m->vhash, hv); +struct multi_route *r =NULL ; + +/* if route currently exists, get the instance which owns it */ + he =hash_lookup_fast (m->vhash, bucket, addr, hv); +if (he) + { + r = (struct multi_route *)he->value; + } + +/* if the route does not exist or exists but is not owned by the current instance, return */ +if (!r || r->instance != mi) + { +return ; + } + +struct gc_arena gc =gc_new (); +msg (D_MULTI_LOW ,"MULTI: Unlearn: %s -> %s" ,mroute_addr_print (&r->addr, &gc),multi_instance_string (mi, false, &gc)); +learn_address_script (m,NULL ,"delete" , &r->addr); +hash_remove_by_value (m->vhash, r); +multi_route_del (r); + +gc_free (&gc); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a The new IPv4 address in network byte order +*/ +static void +multi_unlearn_in_addr_t (struct multi_context *m,struct multi_instance *mi,in_addr_t a) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV4 ; + addr.len =4 ; + addr.v4.addr = a; + +multi_unlearn_addr (m, mi, &addr); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a6 The new IPv6 address +*/ +static void +multi_unlearn_in6_addr (struct multi_context *m,struct multi_instance *mi,struct in6_addr a6) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV6 ; + addr.len =16 ; + addr.v6.addr = a6; + +multi_unlearn_addr (m, mi, &addr); +} + +/* Function to unlearn previous ifconfig of a client in the server multi_context after a PUSH_UPDATE */ +void +unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi) +{ +in_addr_t old_addr =0 ; + old_addr =htonl (mi->context.c2.push_ifconfig_local); +multi_unlearn_in_addr_t (m, mi, old_addr); + mi->context.c2.push_ifconfig_defined = false; + mi->context.c2.push_ifconfig_local =0 ; +} + +/* Function to unlearn previous ifconfig-ipv6 of a client in the server multi_context after a PUSH_UPDATE */ +void +unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi) +{ +struct in6_addr old_addr6; +CLEAR (old_addr6); + old_addr6 = mi->context.c2.push_ifconfig_ipv6_local; +multi_unlearn_in6_addr (m, mi, old_addr6); + mi->context.c2.push_ifconfig_ipv6_defined = false; +CLEAR (mi->context.c2.push_ifconfig_ipv6_local); +} +/** * Update the vhash with new IP/IPv6 addresses in the multi_context when a * push-update message containing ifconfig/ifconfig-ipv6 options is sent -* from the server. This function should be called after a push-update -* and old_ip/old_ipv6 are the previous addresses of the client in -* ctx->options.ifconfig_local and ctx->options.ifconfig_ipv6_local. +* from the server. +* +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param new_ip The new IPv4 address or NULL if no change +* @param new_ipv6 The new IPv6 address or NULL if no change */ void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) { -struct in_addr addr; -struct in6_addr new_ipv6; - -if ((mi->context.options.ifconfig_local && (!old_ip ||strcmp (old_ip, mi->context.options.ifconfig_local))) - &&inet_pton (AF_INET , mi->context.options.ifconfig_local, &addr) ==1 ) +if (new_ip) { -in_addr_t new_ip =ntohl (addr.s_addr); +/* Remove old IP */ +if (mi->context.c2.push_ifconfig_defined) + { +unlearn_ifconfig (m, mi); + }/* Add new IP */ -multi_learn_in_addr_t (m, mi, new_ip,-1 , true); +struct in_addr new_addr; +CLEAR (new_addr); +if (inet_pton (AF_INET , new_ip, &new_addr) ==1 + &&multi_learn_in_addr_t (m, mi,ntohl (new_addr.s_addr),-1 , true)) + { + mi->context.c2.push_ifconfig_defined = true; + mi->context.c2.push_ifconfig_local =ntohl (new_addr.s_addr); + } } -/* TO DO: -* else if (old_ip) -* { -* // remove old IP -* } -*/ - -if ((mi->context.options.ifconfig_ipv6_local && (!old_ipv6 ||strcmp (old_ipv6, mi->context.options.ifconfig_ipv6_local))) - &&inet_pton (AF_INET6 , mi->context.options.ifconfig_ipv6_local, &new_ipv6) ==1 ) +if (new_ipv6) { -/* Add new IPv6 */ -multi_learn_in6_addr (m, mi, new_ipv6,-1 , true); - } +/* Remove old IPv6 */ +if (mi->context.c2.push_ifconfig_ipv6_defined) + { +unlearn_ifconfig_ipv6 (m, mi); + } -/* TO DO: -* else if (old_ipv6) -* { -* // remove old IPv6 -* } -*/ +/* Add new IPv6 */ +struct in6_addr new_addr6; +CLEAR (new_addr6); +if (inet_pton (AF_INET6 , new_ipv6, &new_addr6) ==1 + &&multi_learn_in6_addr (m, mi, new_addr6,-1 , true)) + { + mi->context.c2.push_ifconfig_ipv6_defined = true; + mi->context.c2.push_ifconfig_ipv6_local = new_addr6; + } + } }
src/openvpn/multi.h +3 -1
@@ -692,6 +692,8 @@#endif void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6); +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6); +void unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi); +void unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi);#endif /* MULTI_H */
src/openvpn/push.c +1 -1
@@ -1118,7 +1118,7 @@ " To be able to process PUSH_UPDATE messages, be sure to use the --disable-dco option.");return PUSH_MSG_ERROR ; } -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
src/openvpn/push.h +5 -4
@@ -61,11 +61,13 @@* message has not yet been received. * * @param c The context for the operation. +* @param o The options structure to be updated with the received push options. * @param permission_mask The permission mask specifying which options are allowed to be pulled. * @param option_types_found A pointer to a variable that will be filled with the types of options * found in the message. * @param buf A buffer containing the received message. -* @param msg_sender A boolean indicating if function is called by the message sender (server). +* @param msg_sender A boolean indicating if the message is being processed on the client (false) +* or on the server (true). * * @return * - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied.
@@ -74,9 +76,8 @@* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. */ -int process_incoming_push_update (struct context *c,unsigned int permission_mask, -unsigned int *option_types_found,struct buffer *buf, -bool msg_sender); +int process_push_update (struct context *c,struct options *o,unsigned int permission_mask, +unsigned int *option_types_found,struct buffer *buf,bool msg_sender); int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options, unsigned int permission_mask,
src/openvpn/push_util.c +55 -35
158 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +14 -2
@@ -29,7 +29,19 @@ }void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi) +{ +return ; +} + +void +unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi) +{ +return ; +} + +void +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) {return ; }
@@ -95,7 +107,7 @@ }else if (honor_received_options &&buf_string_compare_advance (&buf, push_update_cmd)) { -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 7
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Attention is currently required from: cron2, flichtenheld, ordex, plaisthos.
mrbff has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email )
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
Patch Set 7:
(1 comment)
File src/openvpn/multi.c:
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/336a1785_981fff39?usp=email :
PS5, Line 4390: mi->context.c2.push_ifconfig_local = htonl(new_addr.s_addr);
Quoted 1 line
yes I printed bit by bit and they are the same and I don't understand why htonl fixes things and I d […]
Actually the problem was: push_ifconfig needed ntohl, not htonl but they do the same thing so it worked and i also was convinced for some reason that push_ifconfig needed network order, silly me.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 7
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Tue, 14 Oct 2025 20:20:37 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: ordex <[email protected]...>
Comment-In-Reply-To: mrbff <[email protected]...>
Attention is currently required from: flichtenheld, mrbff, ordex, plaisthos.
cron2 has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email )
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
Patch Set 7: Code-Review+2
(3 comments)
Patchset:
PS7:
This looks good now. Tested a sequence of "change ifconfig, change ifconfig, change to -ifconfig, send new ifconfig" and it always learned/unlearned the expected things
``` Oct 17 22:11:37 gentoo tun-udp-p2mp[13761]: MULTI: Learn: 10.204.2.46 -> freebsd-14-amd64/udp6:194.97.140.5:60204 Oct 17 22:11:37 gentoo tun-udp-p2mp[13761]: MULTI: primary virtual IP for freebsd-14-amd64/udp6:194.97.140.5:60204: 10.204.2.46 Oct 17 22:11:37 gentoo tun-udp-p2mp[13761]: MULTI: Learn: fd00:abcd:204:2::100a -> freebsd-14-amd64/udp6:194.97.140.5:60204 Oct 17 22:11:37 gentoo tun-udp-p2mp[13761]: MULTI: primary virtual IPv6 for freebsd-14-amd64/udp6:194.97.140.5:60204: fd00:abcd:204:2::100a Oct 17 22:13:15 gentoo tun-udp-p2mp[13761]: MULTI: Unlearn: 10.204.2.46 -> freebsd-14-amd64/udp6:194.97.140.5:60204 Oct 17 22:13:15 gentoo tun-udp-p2mp[13761]: MULTI: Learn: 10.204.2.99 -> freebsd-14-amd64/udp6:194.97.140.5:60204 Oct 17 22:13:38 gentoo tun-udp-p2mp[13761]: MULTI: Unlearn: 10.204.2.99 -> freebsd-14-amd64/udp6:194.97.140.5:60204 Oct 17 22:13:38 gentoo tun-udp-p2mp[13761]: MULTI: Learn: 10.204.2.146 -> freebsd-14-amd64/udp6:194.97.140.5:60204 Oct 17 22:14:40 gentoo tun-udp-p2mp[13761]: MULTI: Unlearn: 10.204.2.146 -> freebsd-14-amd64/udp6:194.97.140.5:60204 Oct 17 22:14:57 gentoo tun-udp-p2mp[13761]: MULTI: Learn: 10.204.2.99 -> freebsd-14-amd64/udp6:194.97.140.5:60204 ```
also the logging is symmetric now (thanks again). Very nice.
I also tested IPv6, though it mains me to send "PUSH_UPDATE,-ifconfig-ipv6" - but it still works :-)
File src/openvpn/push_util.c:
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/831de5dd_a3d9baac?usp=email :
PS6, Line 165: o.ifconfig_local = canary;
Quoted 1 line
the canary is mostly to be less invasive as possible. […]
Done
http://gerrit.openvpn.net/c/openvpn/+/1253/comment/baeb5012_d8c04c16?usp=email :
PS6, Line 166: o.ifconfig_ipv6_local = canary;
Quoted 1 line
same for this obviously.
While I agree that this is not pretty, I would still leave it at that (and mrbff admitted that "it is ugly"). I do like the rest of the code a lot in this latest iteration, and want to move it forward so it's in beta4... so I'm willing to accept this part of limited beauty. We can improve it later - right now it's "not working" which is definitely less useful ;-)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 7
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Fri, 17 Oct 2025 20:18:52 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: ordex <[email protected]...>
Comment-In-Reply-To: mrbff <[email protected]...>
PATCH v7 1/1 PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
In reply to a message not in the archiveFrom: Marco Baffo <[email protected]...>
When sending a PUSH_UPDATE containing an ifconfig(-ipv6) option, we must add the new IP to the multi_context vhash (hash table of the clients indexed by virtual IPs). Now in addition to adding new client IPs, old IPs are also removed from vhash, allowing for a more complete update.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1253
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1253
This mail reflects revision 7 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
src/openvpn/multi.c +127 -29
@@ -4269,46 +4269,144 @@close_instance (top); } +/* Searches for the address and deletes it if it is owned by the multi_instance */ +static void +multi_unlearn_addr (struct multi_context *m,struct multi_instance *mi,const struct mroute_addr *addr) +{ +struct hash_element *he; +const uint32_t hv =hash_value (m->vhash, addr); +struct hash_bucket *bucket =hash_bucket (m->vhash, hv); +struct multi_route *r =NULL ; + +/* if route currently exists, get the instance which owns it */ + he =hash_lookup_fast (m->vhash, bucket, addr, hv); +if (he) + { + r = (struct multi_route *)he->value; + } + +/* if the route does not exist or exists but is not owned by the current instance, return */ +if (!r || r->instance != mi) + { +return ; + } + +struct gc_arena gc =gc_new (); +msg (D_MULTI_LOW ,"MULTI: Unlearn: %s -> %s" ,mroute_addr_print (&r->addr, &gc),multi_instance_string (mi, false, &gc)); +learn_address_script (m,NULL ,"delete" , &r->addr); +hash_remove_by_value (m->vhash, r); +multi_route_del (r); + +gc_free (&gc); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a The new IPv4 address in network byte order +*/ +static void +multi_unlearn_in_addr_t (struct multi_context *m,struct multi_instance *mi,in_addr_t a) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV4 ; + addr.len =4 ; + addr.v4.addr = a; + +multi_unlearn_addr (m, mi, &addr); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a6 The new IPv6 address +*/ +static void +multi_unlearn_in6_addr (struct multi_context *m,struct multi_instance *mi,struct in6_addr a6) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV6 ; + addr.len =16 ; + addr.v6.addr = a6; + +multi_unlearn_addr (m, mi, &addr); +} + +/* Function to unlearn previous ifconfig of a client in the server multi_context after a PUSH_UPDATE */ +void +unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi) +{ +in_addr_t old_addr =0 ; + old_addr =htonl (mi->context.c2.push_ifconfig_local); +multi_unlearn_in_addr_t (m, mi, old_addr); + mi->context.c2.push_ifconfig_defined = false; + mi->context.c2.push_ifconfig_local =0 ; +} + +/* Function to unlearn previous ifconfig-ipv6 of a client in the server multi_context after a PUSH_UPDATE */ +void +unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi) +{ +struct in6_addr old_addr6; +CLEAR (old_addr6); + old_addr6 = mi->context.c2.push_ifconfig_ipv6_local; +multi_unlearn_in6_addr (m, mi, old_addr6); + mi->context.c2.push_ifconfig_ipv6_defined = false; +CLEAR (mi->context.c2.push_ifconfig_ipv6_local); +} +/** * Update the vhash with new IP/IPv6 addresses in the multi_context when a * push-update message containing ifconfig/ifconfig-ipv6 options is sent -* from the server. This function should be called after a push-update -* and old_ip/old_ipv6 are the previous addresses of the client in -* ctx->options.ifconfig_local and ctx->options.ifconfig_ipv6_local. +* from the server. +* +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param new_ip The new IPv4 address or NULL if no change +* @param new_ipv6 The new IPv6 address or NULL if no change */ void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) { -struct in_addr addr; -struct in6_addr new_ipv6; - -if ((mi->context.options.ifconfig_local && (!old_ip ||strcmp (old_ip, mi->context.options.ifconfig_local))) - &&inet_pton (AF_INET , mi->context.options.ifconfig_local, &addr) ==1 ) +if (new_ip) { -in_addr_t new_ip =ntohl (addr.s_addr); +/* Remove old IP */ +if (mi->context.c2.push_ifconfig_defined) + { +unlearn_ifconfig (m, mi); + }/* Add new IP */ -multi_learn_in_addr_t (m, mi, new_ip,-1 , true); +struct in_addr new_addr; +CLEAR (new_addr); +if (inet_pton (AF_INET , new_ip, &new_addr) ==1 + &&multi_learn_in_addr_t (m, mi,ntohl (new_addr.s_addr),-1 , true)) + { + mi->context.c2.push_ifconfig_defined = true; + mi->context.c2.push_ifconfig_local =ntohl (new_addr.s_addr); + } } -/* TO DO: -* else if (old_ip) -* { -* // remove old IP -* } -*/ - -if ((mi->context.options.ifconfig_ipv6_local && (!old_ipv6 ||strcmp (old_ipv6, mi->context.options.ifconfig_ipv6_local))) - &&inet_pton (AF_INET6 , mi->context.options.ifconfig_ipv6_local, &new_ipv6) ==1 ) +if (new_ipv6) { -/* Add new IPv6 */ -multi_learn_in6_addr (m, mi, new_ipv6,-1 , true); - } +/* Remove old IPv6 */ +if (mi->context.c2.push_ifconfig_ipv6_defined) + { +unlearn_ifconfig_ipv6 (m, mi); + } -/* TO DO: -* else if (old_ipv6) -* { -* // remove old IPv6 -* } -*/ +/* Add new IPv6 */ +struct in6_addr new_addr6; +CLEAR (new_addr6); +if (inet_pton (AF_INET6 , new_ipv6, &new_addr6) ==1 + &&multi_learn_in6_addr (m, mi, new_addr6,-1 , true)) + { + mi->context.c2.push_ifconfig_ipv6_defined = true; + mi->context.c2.push_ifconfig_ipv6_local = new_addr6; + } + } }
src/openvpn/multi.h +3 -1
@@ -692,6 +692,8 @@#endif void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6); +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6); +void unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi); +void unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi);#endif /* MULTI_H */
src/openvpn/push.c +1 -1
@@ -1118,7 +1118,7 @@ " To be able to process PUSH_UPDATE messages, be sure to use the --disable-dco option.");return PUSH_MSG_ERROR ; } -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
src/openvpn/push.h +5 -4
@@ -61,11 +61,13 @@* message has not yet been received. * * @param c The context for the operation. +* @param o The options structure to be updated with the received push options. * @param permission_mask The permission mask specifying which options are allowed to be pulled. * @param option_types_found A pointer to a variable that will be filled with the types of options * found in the message. * @param buf A buffer containing the received message. -* @param msg_sender A boolean indicating if function is called by the message sender (server). +* @param msg_sender A boolean indicating if the message is being processed on the client (false) +* or on the server (true). * * @return * - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied.
@@ -74,9 +76,8 @@* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. */ -int process_incoming_push_update (struct context *c,unsigned int permission_mask, -unsigned int *option_types_found,struct buffer *buf, -bool msg_sender); +int process_push_update (struct context *c,struct options *o,unsigned int permission_mask, +unsigned int *option_types_found,struct buffer *buf,bool msg_sender); int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options, unsigned int permission_mask,
src/openvpn/push_util.c +55 -35
158 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +14 -2
@@ -29,7 +29,19 @@ }void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi) +{ +return ; +} + +void +unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi) +{ +return ; +} + +void +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) {return ; }
@@ -95,7 +107,7 @@ }else if (honor_received_options &&buf_string_compare_advance (&buf, push_update_cmd)) { -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
[Openvpn-devel] [PATCH applied] Re: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
So - threw this into the server/client test, which absolutely does not excercise the code paths changed here (but it ensure that nothing else gets broken). Then, used one of the server instances to PUSH_UPDATE ifconfig/ifconfig-ipv6 changes (A->B->C and A->B->C->nothing->B and "IPv6 to nothing, IPv4 to B" in the same message) and it was all very well behaved, and the logging is nicely symmetric as well
MULTI: Unlearn: fd00:abcd:204:2::100a -> freebsd-14-amd64/udp6:...
MULTI: Learn: fd00:abcd:204:2::9999 -> freebsd-14-amd64/udp6:...
MULTI: Unlearn: fd00:abcd:204:2::9999 -> freebsd-14-amd64/udp6:...
MULTI: Unlearn: 10.204.2.99 -> freebsd-14-amd64/udp6:...
MULTI: Learn: 10.204.2.146 -> freebsd-14-amd64/udp6:...(we tried to make this use the mi prefix, but as "Learn" is not using it, it looked silly - this way in v5+ is nice).
Oh, yes, and I stared long and hard at the code and asked for lots of changes :-) so this has been scrutiniced quite a bit.
I did not test --learn-address, tbh. But the code looks like all the other invocations, so I assume it will work.
Nice side bonus - the mail-archive list is actually talking to me again, for a change, so I can proper reference the patch.
Your patch has been applied to the master branch.
commit 5e4c9a69eaf9d32e85613bd71ed219fdbb062d34
Author: Marco Baffo Date: Fri Oct 17 22:19:12 2025 +0200
PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
Signed-off-by: Marco Baffo <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1253
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg33412.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#8) to the change originally created by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by cron2
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
When sending a PUSH_UPDATE containing an ifconfig(-ipv6) option, we must add the new IP to the multi_context vhash (hash table of the clients indexed by virtual IPs). Now in addition to adding new client IPs, old IPs are also removed from vhash, allowing for a more complete update.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1253
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg33412.html
---
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/push_util.c
M tests/unit_tests/openvpn/test_push_update_msg.c
6 files changed, 205 insertions(+), 72 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/53/1253/8
src/openvpn/multi.c +127 -29
@@ -4269,46 +4269,144 @@close_instance (top); } +/* Searches for the address and deletes it if it is owned by the multi_instance */ +static void +multi_unlearn_addr (struct multi_context *m,struct multi_instance *mi,const struct mroute_addr *addr) +{ +struct hash_element *he; +const uint32_t hv =hash_value (m->vhash, addr); +struct hash_bucket *bucket =hash_bucket (m->vhash, hv); +struct multi_route *r =NULL ; + +/* if route currently exists, get the instance which owns it */ + he =hash_lookup_fast (m->vhash, bucket, addr, hv); +if (he) + { + r = (struct multi_route *)he->value; + } + +/* if the route does not exist or exists but is not owned by the current instance, return */ +if (!r || r->instance != mi) + { +return ; + } + +struct gc_arena gc =gc_new (); +msg (D_MULTI_LOW ,"MULTI: Unlearn: %s -> %s" ,mroute_addr_print (&r->addr, &gc),multi_instance_string (mi, false, &gc)); +learn_address_script (m,NULL ,"delete" , &r->addr); +hash_remove_by_value (m->vhash, r); +multi_route_del (r); + +gc_free (&gc); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a The new IPv4 address in network byte order +*/ +static void +multi_unlearn_in_addr_t (struct multi_context *m,struct multi_instance *mi,in_addr_t a) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV4 ; + addr.len =4 ; + addr.v4.addr = a; + +multi_unlearn_addr (m, mi, &addr); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a6 The new IPv6 address +*/ +static void +multi_unlearn_in6_addr (struct multi_context *m,struct multi_instance *mi,struct in6_addr a6) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV6 ; + addr.len =16 ; + addr.v6.addr = a6; + +multi_unlearn_addr (m, mi, &addr); +} + +/* Function to unlearn previous ifconfig of a client in the server multi_context after a PUSH_UPDATE */ +void +unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi) +{ +in_addr_t old_addr =0 ; + old_addr =htonl (mi->context.c2.push_ifconfig_local); +multi_unlearn_in_addr_t (m, mi, old_addr); + mi->context.c2.push_ifconfig_defined = false; + mi->context.c2.push_ifconfig_local =0 ; +} + +/* Function to unlearn previous ifconfig-ipv6 of a client in the server multi_context after a PUSH_UPDATE */ +void +unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi) +{ +struct in6_addr old_addr6; +CLEAR (old_addr6); + old_addr6 = mi->context.c2.push_ifconfig_ipv6_local; +multi_unlearn_in6_addr (m, mi, old_addr6); + mi->context.c2.push_ifconfig_ipv6_defined = false; +CLEAR (mi->context.c2.push_ifconfig_ipv6_local); +} +/** * Update the vhash with new IP/IPv6 addresses in the multi_context when a * push-update message containing ifconfig/ifconfig-ipv6 options is sent -* from the server. This function should be called after a push-update -* and old_ip/old_ipv6 are the previous addresses of the client in -* ctx->options.ifconfig_local and ctx->options.ifconfig_ipv6_local. +* from the server. +* +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param new_ip The new IPv4 address or NULL if no change +* @param new_ipv6 The new IPv6 address or NULL if no change */ void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) { -struct in_addr addr; -struct in6_addr new_ipv6; - -if ((mi->context.options.ifconfig_local && (!old_ip ||strcmp (old_ip, mi->context.options.ifconfig_local))) - &&inet_pton (AF_INET , mi->context.options.ifconfig_local, &addr) ==1 ) +if (new_ip) { -in_addr_t new_ip =ntohl (addr.s_addr); +/* Remove old IP */ +if (mi->context.c2.push_ifconfig_defined) + { +unlearn_ifconfig (m, mi); + }/* Add new IP */ -multi_learn_in_addr_t (m, mi, new_ip,-1 , true); +struct in_addr new_addr; +CLEAR (new_addr); +if (inet_pton (AF_INET , new_ip, &new_addr) ==1 + &&multi_learn_in_addr_t (m, mi,ntohl (new_addr.s_addr),-1 , true)) + { + mi->context.c2.push_ifconfig_defined = true; + mi->context.c2.push_ifconfig_local =ntohl (new_addr.s_addr); + } } -/* TO DO: -* else if (old_ip) -* { -* // remove old IP -* } -*/ - -if ((mi->context.options.ifconfig_ipv6_local && (!old_ipv6 ||strcmp (old_ipv6, mi->context.options.ifconfig_ipv6_local))) - &&inet_pton (AF_INET6 , mi->context.options.ifconfig_ipv6_local, &new_ipv6) ==1 ) +if (new_ipv6) { -/* Add new IPv6 */ -multi_learn_in6_addr (m, mi, new_ipv6,-1 , true); - } +/* Remove old IPv6 */ +if (mi->context.c2.push_ifconfig_ipv6_defined) + { +unlearn_ifconfig_ipv6 (m, mi); + } -/* TO DO: -* else if (old_ipv6) -* { -* // remove old IPv6 -* } -*/ +/* Add new IPv6 */ +struct in6_addr new_addr6; +CLEAR (new_addr6); +if (inet_pton (AF_INET6 , new_ipv6, &new_addr6) ==1 + &&multi_learn_in6_addr (m, mi, new_addr6,-1 , true)) + { + mi->context.c2.push_ifconfig_ipv6_defined = true; + mi->context.c2.push_ifconfig_ipv6_local = new_addr6; + } + } }
src/openvpn/multi.h +3 -1
@@ -692,6 +692,8 @@#endif void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6); +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6); +void unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi); +void unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi);#endif /* MULTI_H */
src/openvpn/push.c +1 -1
@@ -1118,7 +1118,7 @@ " To be able to process PUSH_UPDATE messages, be sure to use the --disable-dco option.");return PUSH_MSG_ERROR ; } -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
src/openvpn/push.h +5 -4
@@ -61,11 +61,13 @@* message has not yet been received. * * @param c The context for the operation. +* @param o The options structure to be updated with the received push options. * @param permission_mask The permission mask specifying which options are allowed to be pulled. * @param option_types_found A pointer to a variable that will be filled with the types of options * found in the message. * @param buf A buffer containing the received message. -* @param msg_sender A boolean indicating if function is called by the message sender (server). +* @param msg_sender A boolean indicating if the message is being processed on the client (false) +* or on the server (true). * * @return * - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied.
@@ -74,9 +76,8 @@* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. */ -int process_incoming_push_update (struct context *c,unsigned int permission_mask, -unsigned int *option_types_found,struct buffer *buf, -bool msg_sender); +int process_push_update (struct context *c,struct options *o,unsigned int permission_mask, +unsigned int *option_types_found,struct buffer *buf,bool msg_sender); int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options, unsigned int permission_mask,
src/openvpn/push_util.c +55 -35
158 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +14 -2
@@ -29,7 +29,19 @@ }void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi) +{ +return ; +} + +void +unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi) +{ +return ; +} + +void +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) {return ; }
@@ -95,7 +107,7 @@ }else if (honor_received_options &&buf_string_compare_advance (&buf, push_update_cmd)) { -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 8
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email )
Change subject: PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
......................................................................
PUSH_UPDATE server: remove old IP(s) from vhash after sending a message containing ifconfig(-ipv6)
When sending a PUSH_UPDATE containing an ifconfig(-ipv6) option, we must add the new IP to the multi_context vhash (hash table of the clients indexed by virtual IPs). Now in addition to adding new client IPs, old IPs are also removed from vhash, allowing for a more complete update.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1253
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg33412.html
---
M src/openvpn/multi.c
M src/openvpn/multi.h
M src/openvpn/push.c
M src/openvpn/push.h
M src/openvpn/push_util.c
M tests/unit_tests/openvpn/test_push_update_msg.c
6 files changed, 205 insertions(+), 72 deletions(-)
src/openvpn/multi.c +127 -29
@@ -4269,46 +4269,144 @@close_instance (top); } +/* Searches for the address and deletes it if it is owned by the multi_instance */ +static void +multi_unlearn_addr (struct multi_context *m,struct multi_instance *mi,const struct mroute_addr *addr) +{ +struct hash_element *he; +const uint32_t hv =hash_value (m->vhash, addr); +struct hash_bucket *bucket =hash_bucket (m->vhash, hv); +struct multi_route *r =NULL ; + +/* if route currently exists, get the instance which owns it */ + he =hash_lookup_fast (m->vhash, bucket, addr, hv); +if (he) + { + r = (struct multi_route *)he->value; + } + +/* if the route does not exist or exists but is not owned by the current instance, return */ +if (!r || r->instance != mi) + { +return ; + } + +struct gc_arena gc =gc_new (); +msg (D_MULTI_LOW ,"MULTI: Unlearn: %s -> %s" ,mroute_addr_print (&r->addr, &gc),multi_instance_string (mi, false, &gc)); +learn_address_script (m,NULL ,"delete" , &r->addr); +hash_remove_by_value (m->vhash, r); +multi_route_del (r); + +gc_free (&gc); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a The new IPv4 address in network byte order +*/ +static void +multi_unlearn_in_addr_t (struct multi_context *m,struct multi_instance *mi,in_addr_t a) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV4 ; + addr.len =4 ; + addr.v4.addr = a; + +multi_unlearn_addr (m, mi, &addr); +} + +/** +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param a6 The new IPv6 address +*/ +static void +multi_unlearn_in6_addr (struct multi_context *m,struct multi_instance *mi,struct in6_addr a6) +{ +struct mroute_addr addr; +CLEAR (addr); + + addr.type =MR_ADDR_IPV6 ; + addr.len =16 ; + addr.v6.addr = a6; + +multi_unlearn_addr (m, mi, &addr); +} + +/* Function to unlearn previous ifconfig of a client in the server multi_context after a PUSH_UPDATE */ +void +unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi) +{ +in_addr_t old_addr =0 ; + old_addr =htonl (mi->context.c2.push_ifconfig_local); +multi_unlearn_in_addr_t (m, mi, old_addr); + mi->context.c2.push_ifconfig_defined = false; + mi->context.c2.push_ifconfig_local =0 ; +} + +/* Function to unlearn previous ifconfig-ipv6 of a client in the server multi_context after a PUSH_UPDATE */ +void +unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi) +{ +struct in6_addr old_addr6; +CLEAR (old_addr6); + old_addr6 = mi->context.c2.push_ifconfig_ipv6_local; +multi_unlearn_in6_addr (m, mi, old_addr6); + mi->context.c2.push_ifconfig_ipv6_defined = false; +CLEAR (mi->context.c2.push_ifconfig_ipv6_local); +} +/** * Update the vhash with new IP/IPv6 addresses in the multi_context when a * push-update message containing ifconfig/ifconfig-ipv6 options is sent -* from the server. This function should be called after a push-update -* and old_ip/old_ipv6 are the previous addresses of the client in -* ctx->options.ifconfig_local and ctx->options.ifconfig_ipv6_local. +* from the server. +* +* @param m The multi_context +* @param mi The multi_instance of the client we are updating +* @param new_ip The new IPv4 address or NULL if no change +* @param new_ipv6 The new IPv6 address or NULL if no change */ void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) { -struct in_addr addr; -struct in6_addr new_ipv6; - -if ((mi->context.options.ifconfig_local && (!old_ip ||strcmp (old_ip, mi->context.options.ifconfig_local))) - &&inet_pton (AF_INET , mi->context.options.ifconfig_local, &addr) ==1 ) +if (new_ip) { -in_addr_t new_ip =ntohl (addr.s_addr); +/* Remove old IP */ +if (mi->context.c2.push_ifconfig_defined) + { +unlearn_ifconfig (m, mi); + }/* Add new IP */ -multi_learn_in_addr_t (m, mi, new_ip,-1 , true); +struct in_addr new_addr; +CLEAR (new_addr); +if (inet_pton (AF_INET , new_ip, &new_addr) ==1 + &&multi_learn_in_addr_t (m, mi,ntohl (new_addr.s_addr),-1 , true)) + { + mi->context.c2.push_ifconfig_defined = true; + mi->context.c2.push_ifconfig_local =ntohl (new_addr.s_addr); + } } -/* TO DO: -* else if (old_ip) -* { -* // remove old IP -* } -*/ - -if ((mi->context.options.ifconfig_ipv6_local && (!old_ipv6 ||strcmp (old_ipv6, mi->context.options.ifconfig_ipv6_local))) - &&inet_pton (AF_INET6 , mi->context.options.ifconfig_ipv6_local, &new_ipv6) ==1 ) +if (new_ipv6) { -/* Add new IPv6 */ -multi_learn_in6_addr (m, mi, new_ipv6,-1 , true); - } +/* Remove old IPv6 */ +if (mi->context.c2.push_ifconfig_ipv6_defined) + { +unlearn_ifconfig_ipv6 (m, mi); + } -/* TO DO: -* else if (old_ipv6) -* { -* // remove old IPv6 -* } -*/ +/* Add new IPv6 */ +struct in6_addr new_addr6; +CLEAR (new_addr6); +if (inet_pton (AF_INET6 , new_ipv6, &new_addr6) ==1 + &&multi_learn_in6_addr (m, mi, new_addr6,-1 , true)) + { + mi->context.c2.push_ifconfig_ipv6_defined = true; + mi->context.c2.push_ifconfig_ipv6_local = new_addr6; + } + } }
src/openvpn/multi.h +3 -1
@@ -692,6 +692,8 @@#endif void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6); +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6); +void unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi); +void unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi);#endif /* MULTI_H */
src/openvpn/push.c +1 -1
@@ -1118,7 +1118,7 @@ " To be able to process PUSH_UPDATE messages, be sure to use the --disable-dco option.");return PUSH_MSG_ERROR ; } -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
src/openvpn/push.h +5 -4
@@ -61,11 +61,13 @@* message has not yet been received. * * @param c The context for the operation. +* @param o The options structure to be updated with the received push options. * @param permission_mask The permission mask specifying which options are allowed to be pulled. * @param option_types_found A pointer to a variable that will be filled with the types of options * found in the message. * @param buf A buffer containing the received message. -* @param msg_sender A boolean indicating if function is called by the message sender (server). +* @param msg_sender A boolean indicating if the message is being processed on the client (false) +* or on the server (true). * * @return * - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied.
@@ -74,9 +76,8 @@* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. */ -int process_incoming_push_update (struct context *c,unsigned int permission_mask, -unsigned int *option_types_found,struct buffer *buf, -bool msg_sender); +int process_push_update (struct context *c,struct options *o,unsigned int permission_mask, +unsigned int *option_types_found,struct buffer *buf,bool msg_sender); int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options, unsigned int permission_mask,
src/openvpn/push_util.c +55 -35
158 lines not on this page · raw message
tests/unit_tests/openvpn/test_push_update_msg.c +14 -2
@@ -29,7 +29,19 @@ }void -update_vhash (struct multi_context *m,struct multi_instance *mi,const char *old_ip,const char *old_ipv6) +unlearn_ifconfig (struct multi_context *m,struct multi_instance *mi) +{ +return ; +} + +void +unlearn_ifconfig_ipv6 (struct multi_context *m,struct multi_instance *mi) +{ +return ; +} + +void +update_vhash (struct multi_context *m,struct multi_instance *mi,const char *new_ip,const char *new_ipv6) {return ; }
@@ -95,7 +107,7 @@ }else if (honor_received_options &&buf_string_compare_advance (&buf, push_update_cmd)) { -return process_incoming_push_update (c, permission_mask, option_types_found, &buf, false); +return process_push_update (c, &c->options, permission_mask, option_types_found, &buf, false); }else {
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1253?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I07a8ddd9026eef64b6f5abde98702a9801616a5f
Gerrit-Change-Number: 1253
Gerrit-PatchSet: 8
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: ordex <[email protected]...>